home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / RUN.TST / SETRUN.C < prev    next >
C/C++ Source or Header  |  1996-03-26  |  3KB  |  79 lines

  1. /* ============ */
  2. /* setrun.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <rundefs.h>
  6. #include <math.h>
  7. #include <mconf.h>
  8. #include <miscdefs.h>
  9.  
  10. #define    ACT(X)    #X
  11.  
  12. #define    CLAMP(Out, Var, Lo, Hi)    Out = __min(Hi, __max(Lo, Var))
  13.  
  14. #define    EXPECT_LABEL    "Expected No. Events for Each Category"
  15.  
  16. #define    NEED_ALL(Label)    "Enter "Label
  17.  
  18. #define    NEED_USER_ENTRY(LABEL, LO, HI) \
  19.     NEED_ALL(LABEL" ["ACT(LO)"-"ACT(HI)"]: ")
  20.  
  21. #define    REPORT_USER_INT_ENTRY(Entry, Label)        \
  22.     {                            \
  23.     fflush(NULL); printf("\n");            \
  24.     printf("\tNumber Entered: %.f", (double)Entry);    \
  25.     printf(" (%s)\n", Label);            \
  26.     }
  27. #define    SHOW_INT_VALUE_USED(Entered, Used)             \
  28.     printf("\tTest Value Used: %.f%s\n", (double)Used,    \
  29.     ((double)Entered == (double)Used) ? "" : " (Clamped)")
  30.  
  31. /* ==================================================================== */
  32. /* SetRunControls - Sets Control Parameters for Run Test        */
  33. /* ==================================================================== */
  34. void
  35. SetRunControls(RUN_DATA_STRU * RunData)
  36. {
  37.     int     MinCellExpect, NewlineCh, UserIntEntry;
  38.     double  Mean, StdDev;
  39.  
  40.     NewlineCh = _isatty(_fileno(stdin)) ? '\r' : '\n';
  41.  
  42.     fflush(NULL); fprintf(stderr, "%c", NewlineCh);
  43.     /* ------------------------------------------- */
  44.     /* Get Minimum Expectation for Lowest Category */
  45.     /* ------------------------------------------- */
  46.     GetInt(NEED_USER_ENTRY(EXPECT_LABEL, MIN_CELL_XPCT,
  47.         MAX_CELL_XPCT), &UserIntEntry);
  48.  
  49.     fflush(NULL); fprintf(stderr, "%c", NewlineCh);
  50.  
  51.     REPORT_USER_INT_ENTRY(UserIntEntry, EXPECT_LABEL);
  52.  
  53.     CLAMP(MinCellExpect, UserIntEntry, MIN_CELL_XPCT, MAX_CELL_XPCT);
  54.  
  55.     SHOW_INT_VALUE_USED(UserIntEntry, MinCellExpect);
  56.  
  57.     RunData->NumRand = (UINT)
  58.     floor(0.5 + ((double)MinCellExpect/MIN_CELL_XPCT) * 10000.);
  59.  
  60.     P(printf("Minimum Number of Variates to be Generated = %u\n",
  61.     RunData->NumRand));
  62.  
  63.     /* ------------------------------------------- */
  64.     /* Get Estimate of Number of Variates Required */
  65.     /* ------------------------------------------- */
  66.     RunMeanStdDev((UINT)RAND_MAX+1U, RunData->NumRand, &Mean, &StdDev);
  67.  
  68.     /* ---------------------------------------------------- */
  69.     /* Set MaxGenCount to Keep Generator from Getting Stuck */
  70.     /* ---------------------------------------------------- */
  71.     RunData->MaxGenCount = (long) (Mean + 10 * StdDev);
  72.  
  73.     RunData->TotVariates = 0;
  74.  
  75.     (printf("\nMinimum Number of Variates = %d\n", RunData->NumRand));
  76.     (printf("Maximum Number to Satisfy  = %ld\n", RunData->MaxGenCount));
  77.     fflush(NULL);
  78. }
  79.